package com.liveneo.adapter.outinterface.web.platform;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.liveneo.adapter.base.entity.PrpmCaseInfo;
import com.liveneo.adapter.base.entity.PrpmCaseInfoCyp;
import com.liveneo.adapter.base.entity.PrpmLossItem;
import com.liveneo.adapter.base.entity.PrpmLossItemCyp;
import com.liveneo.adapter.base.entity.PrpmOrg;
import com.liveneo.adapter.base.entity.PrpmSurveyUser;
import com.liveneo.adapter.base.support.LogUtils;
import com.liveneo.adapter.outinterface.util.Constants;
import com.liveneo.adapter.outinterface.util.DBTableUtil;
import com.liveneo.adapter.outinterface.util.DateUtil;
import com.liveneo.adapter.outinterface.util.Encryption;
import com.liveneo.adapter.outinterface.util.HttpRequestUtil;
import com.liveneo.adapter.outinterface.util.JsonUtils;
import com.liveneo.adapter.outinterface.util.ResultInfo;
import com.liveneo.adapter.outinterface.util.StringUtil;
import com.liveneo.adapter.outinterface.util.UUIDUtils;
import com.liveneo.adapter.outinterface.util.UtilValidateModel;
import com.liveneo.adapter.outinterface.web.platform.request.AddSurvry;
import com.liveneo.adapter.outinterface.web.platform.request.BaseRequest;
import com.liveneo.adapter.outinterface.web.platform.request.CaseInfoCancelRequest;
import com.liveneo.adapter.outinterface.web.platform.request.CaseInfoDto;
import com.liveneo.adapter.outinterface.web.platform.request.ChangeCaseVideoRequest;
import com.liveneo.adapter.outinterface.web.platform.request.ChangeTaskStatusRequest;
import com.liveneo.adapter.outinterface.web.platform.request.CliamRequest;
import com.liveneo.adapter.outinterface.web.platform.request.CreateDocumentTask;
import com.liveneo.adapter.outinterface.web.platform.request.DelegateLoss;
import com.liveneo.adapter.outinterface.web.platform.request.DelegateLossInfo;
import com.liveneo.adapter.outinterface.web.platform.request.EndInfoRequest;
import com.liveneo.adapter.outinterface.web.platform.request.GetPaperDocRequest;
import com.liveneo.adapter.outinterface.web.platform.request.InjuryResultBack;
import com.liveneo.adapter.outinterface.web.platform.request.InjuryResultRequest;
import com.liveneo.adapter.outinterface.web.platform.request.InjuryTaskDis;
import com.liveneo.adapter.outinterface.web.platform.request.InjuryTaskDisRequest;
import com.liveneo.adapter.outinterface.web.platform.request.LossItemHistory;
import com.liveneo.adapter.outinterface.web.platform.request.ResponseHead;
import com.liveneo.adapter.outinterface.web.platform.request.ReuploadInfoRequest;
import com.liveneo.adapter.outinterface.web.platform.request.SendSurveyRequest;
import com.liveneo.adapter.outinterface.web.platform.request.SurveyRequest;
import com.liveneo.adapter.outinterface.web.platform.request.SynCheckUser;
import com.liveneo.adapter.outinterface.web.platform.request.VerifyResultInfo;
import com.liveneo.adapter.outinterface.web.platform.response.BaseResponse;
import com.liveneo.adapter.outinterface.web.platform.response.ChangeTaskStatusResponse;
import com.liveneo.adapter.outinterface.web.platform.response.CliamResponse;
import com.liveneo.adapter.outinterface.web.platform.response.GetPaperDocResponse;
import com.liveneo.adapter.outinterface.web.platform.response.SendSurveyInfoResponse;
import com.liveneo.adapter.webservice.client.claim.PolicyInfo;
import com.liveneo.common.utils.JsonUtil;
import com.liveneo.common.utils.Request;

/**
  * @Description: 查勘对外接口
  * @author liveneo-shuqw
  * @date 2016年9月26日 下午4:25:39
  * @Copyright: Copyright (c) 2016 
  * @Company: 北京朗泰
  * @version 3.0
  */
@Controller
@RequestMapping("/surveyPlatform")
public class ClaimController {
	
	@Autowired
	private DBTableUtil dbTableUtil;
	/**
	  * @Title: InjuryTaskDist 人伤预审核任务下发
	  * @Description: 状态：已调;接口名：CLS05
	  * @param @param request
	  * @param @return 设定文件
	  * @return String 返回类型
	  * @throws
	 */
	@RequestMapping("/InjuryTaskDis")
	@ResponseBody
	public String InjuryTaskDist(HttpServletRequest request) {
		BaseResponse response = new BaseResponse(); 
		try {
			//获取参数
			Request<InjuryTaskDisRequest> req =  JsonUtils.fromJsonClaimBase64(request.getInputStream(), InjuryTaskDisRequest.class);
			LogUtils.info("接口精友人伤预审核任务[CLS05----->InjuryTaskDis]接收参数：\n"+JsonUtils.toJson(req)+"\n");	   
			InjuryTaskDisRequest inRequest = JsonUtils.fromJson(JsonUtils.toJson(req.getBusinessBody()), InjuryTaskDisRequest.class);
			InjuryTaskDis it =  inRequest.getInjuryTaskDis();
			//参数校验
			String valdata = UtilValidateModel.validateModel(it);
			if(StringUtils.isNotBlank(valdata)){
				throw new RuntimeException(valdata);
			}
			String orgCode = it.getCompanyUuid(); 	//分公司号
			String caseNo = it.getCaseNo();    		//案件号
			// 设置默认参数
			it.setLossType(Constants.LOSS_ITEMTYPE8);
			it.setVerifyTime("0");
			it.setClaimStatus("2");
			it.setHandleStatus(Constants.LOSS_HANDLESTATUS0);
			it.setCreateTime(new Date());
			it.setUpdateTime(new Date());
			it.setEndCaseTime(new Date());
			it.setCreateUser("95505");
			it.setUpdateUser("95505");
			//日期处理
			String damageDate = DateUtil.formatTimestamp(DateUtil.parseDateTime(it.getDamageDate()));
			it.setDamageDate(damageDate);
			// 查询组织机构
			PrpmOrg prpmOrg = dbTableUtil.selectOrgByCode(orgCode,null);
			if (prpmOrg == null) {
				throw new RuntimeException("查勘平台：分公司代码Code："+ orgCode+"，在查勘未维护或错误");
			}
			// 查询案件信息
			PrpmCaseInfoCyp pc = dbTableUtil.selectCaseInfoCypByNo(caseNo);
			if (pc == null) {
				String caseInfoId =  UUIDUtils.uuid();
				// 新增
				int res = dbTableUtil.saveCaseInfoCyp(it, prpmOrg.getOrgFlag(), orgCode,caseInfoId);
				if (res > 0) {
					dbTableUtil.saveLossItemCyp(it,UUIDUtils.uuid(),caseInfoId);
				}
				response.setErrorMessage("查勘平台:人伤预审核任务下发成功");
				response.setResultCode("000");
				// 推送消息下发
				pushMessageInfoToApp(caseNo, Constants.MOBILE_NEW_TYPE20, it.getContactPhone(), 3, "报案号："+caseNo+" 的人伤预审任务下发成功");

			} else {
				//人伤编号
				String caseInfoCypId = pc.getCaseInfoCypId();
				// 更新
				int res = dbTableUtil.updateCaseInfoCyp(it, prpmOrg.getOrgFlag(), caseInfoCypId , orgCode);
				if (res > 0) {
					PrpmLossItemCyp lossItemCyp= dbTableUtil.selectLossItemCyp(caseNo, it.getLossID(), Constants.LOSS_ITEMTYPE8);
					if (lossItemCyp == null) {
						// 保存人伤信息
						dbTableUtil.saveLossItemCyp(it, UUIDUtils.uuid(), caseInfoCypId);
						response.setErrorMessage("查勘平台:人伤预审核任务成功");
						response.setResultCode("000");
					} else {
						// 是否待审核
						if ("1".equals(lossItemCyp.getHandleStatus())) {
							response.setErrorMessage("查勘平台:已存在待审核的案件，请先审核");
							response.setResultCode("999");
						} else {
							// 备份历史
							int rhis = dbTableUtil.saveLossItemHistryCyp(UUIDUtils.uuid(), lossItemCyp.getLossItemCypId());
							if (rhis > 0) {
								// 更新默认状态
								dbTableUtil.updateLossItemCyp(it,lossItemCyp.getLossItemCypId(),caseInfoCypId);
								response.setErrorMessage("查勘平台:人伤预审核任务成功");
								response.setResultCode("000");
							}
						}
					}
					// 推送消息重派
					pushMessageInfoToApp(caseNo, Constants.MOBILE_NEW_TYPE21, it.getContactPhone(), 3, "报案号："+caseNo+" 的人伤预审任务改派成功");
				}
			}
		} catch (Exception e) {
			LogUtils.error("接口精友人伤预审核任务[CLS05----->InjuryTaskDis]服务器异常：\n",e);
			String msg = "查勘平台：处理精友人伤预审核任务异常";
			if(e instanceof RuntimeException){
				msg = e.getMessage();
			}
			response.setErrorMessage(msg);
			response.setResultCode("999");
		}
		ResponseHead responseHead = ClaimInterface.getResponseHead("CLS05", "InjuryTaskDis");
		responseHead.setErrorMessage(response.getErrorMessage());
		responseHead.setResultCode(response.getResultCode());
		Map<String,Object> param = new HashMap<String,Object>();
		param.put("responseBody", response);
		param.put("responseHead", responseHead);
		LogUtils.info("接口精友人伤预审核任务[CLS05----->InjuryTaskDis]返回结果：\n"+JsonUtils.toJson(param)+"\n");
		String data = Encryption.encryptBASE64(JsonUtil.getJsonString(param), "utf-8");
		return data;
	}
	
	
	
	/**
	  * @Title: injuryResultBack 人伤预审结果
	  * @Description: 状态：已调 ; 接口名：CLS06
	  * @param @param request
	  * @param @return 设定文件
	  * @return String 返回类型
	  * @throws
	 */
	@RequestMapping("/InjuryResultBack")
	@ResponseBody
	public String injuryResultBack(HttpServletRequest request) {
		BaseResponse response = new BaseResponse();
		try {
			//获取参数
			Request<InjuryResultRequest> req =  JsonUtils.fromJsonClaimBase64(request.getInputStream(), InjuryResultRequest.class);
			LogUtils.info("接口人伤预审核任务结果[CLS06----->InjuryResultBack]接收参数：\n"+JsonUtils.toJson(req)+"\n");	  
			InjuryResultRequest inRequest = JsonUtils.fromJson(JsonUtils.toJson(req.getBusinessBody()), InjuryResultRequest.class);
			InjuryResultBack injuryResultBack = inRequest.getInjuryResultBack();
			//参数校验
			String valdata = UtilValidateModel.validateModel(injuryResultBack);
			if(StringUtils.isNotBlank(valdata)){
				throw new RuntimeException(valdata);
			}
			String caseNo = injuryResultBack.getCaseNo(); //案件号
			String lossId = injuryResultBack.getLossID(); //任务号
			PrpmLossItemCyp lossItemCpy = dbTableUtil.selectLossItemCyp(caseNo, lossId, Constants.LOSS_ITEMTYPE8);
			if (lossItemCpy == null) {
				response.setResultCode("999");
				response.setErrorMessage("查勘平台:案件亏损信息不存在，案件号："+ caseNo);
			} else {
				String lossItemCypId = lossItemCpy.getLossItemCypId();
				//删除
				dbTableUtil.deleteLossItemCypById(lossItemCypId);
				
				List<VerifyResultInfo> verifyResultInfos = injuryResultBack.getVerifyResultList();
				for (VerifyResultInfo vr : verifyResultInfos) {
					// 保存人伤信息记录
					dbTableUtil.saveVerifyResultInfo(vr, caseNo, lossItemCpy.getLossId(), lossItemCypId);
				}
				// 修改处理状态  审核完成 状态：2
				dbTableUtil.updateLossItemCypStatusById(Constants.LOSS_HANDLESTATUS2, lossItemCypId);
				response.setResultCode("000");
				response.setErrorMessage("查勘平台:人伤预审结果成功");
				// 推送消息
				pushMessageInfoToApp(caseNo, Constants.MOBILE_NEW_TYPE22, lossItemCpy.getContactPhone(), 3, "报案号："+caseNo+"的人伤预审结果成功");
			}
			
		} catch (Exception e) {
			LogUtils.error("接口人伤预审核任务结果[CLS06----->InjuryResultBack]服务器异常", e);
			response.setResultCode("999");
			response.setErrorMessage("查勘平台:人伤预审核任务结果返回异常");
		}
		ResponseHead responseHead = ClaimInterface.getResponseHead("CLS06", "InjuryResultBack");
		responseHead.setErrorMessage(response.getErrorMessage());
		responseHead.setResultCode(response.getResultCode());
		Map<String,Object> param = new HashMap<String,Object>();
		param.put("responseBody", response);
		param.put("responseHead", responseHead);
		LogUtils.info("接口人伤预审核任务结果[CLS06----->InjuryResultBack]返回结果：\n"+JsonUtils.toJson(param)+"\n");
		String data = Encryption.encryptBASE64(JsonUtil.getJsonString(param), "utf-8");
		return data;
	}
	
	
	/**
	  * @Title: addSurveyOr
	  * 修理厂或查勘同步接口 状态：未调  接口名：CLS04
	  * @param @param request 
	  * @return void
	  * @throws
	 */
	@RequestMapping("/addSurvryor")
	@ResponseBody
	public String addSurveyOr(HttpServletRequest request) {
		//返回结果
		BaseResponse response = new BaseResponse();
		try {
			//参数解析
			Request<AddSurvry> req = JsonUtils.fromJsonClaimBase64(request.getInputStream(), AddSurvry.class);
			LogUtils.info("接口修理厂或查勘同步[CLS04----->addSurveyOr]请求参数：\n"+JsonUtils.toJson(req)+"\n");
			CliamRequest cliamRequest = JsonUtils.fromJson(JsonUtils.toJson(req.getBusinessBody()), CliamRequest.class);
			AddSurvry addSurvry = cliamRequest.getSynSurveyInfo();
			//参数校验
			String valdata = UtilValidateModel.validateModel(addSurvry);
			if(StringUtils.isNotBlank(valdata)){
				throw new RuntimeException(valdata);
			}
			// 查询查勘员信息
			PrpmSurveyUser user = dbTableUtil.selectSurveyUserByCode(addSurvry.getUserCode());
			// 查询组织机构
			PrpmOrg prpmOrg = dbTableUtil.selectOrgByCode(addSurvry.getOrgCode(),null);
			if (prpmOrg == null) {
				throw new RuntimeException("查勘平台：分公司代码Code："+addSurvry.getOrgCode()+"，在查勘未维护或错误");
			}
			// PrpmOrg编号
			String orgId = prpmOrg.getOrgId();
			if (user == null) {
				// 新增
				addSurvry.setCarType(addSurvry.getUserType());
				addSurvry.setUserType("1");
				dbTableUtil.savePrpmSurveyUser(addSurvry, orgId);
			} else {
				// 更新
				addSurvry.setCarType(addSurvry.getUserType());
				addSurvry.setUserType("1");
				dbTableUtil.updatePrpmSurveyUserById(addSurvry, orgId, user.getSurveyUserId());
			}
			response.setErrorMessage("查勘平台：同步查勘员信息成功");
			response.setResultCode("000");
		} catch (Exception e) {
			LogUtils.error("接口修理厂或查勘同步[CLS04----->addSurveyOr]响应异常：", e);
			response.setErrorMessage("同步查勘员异常" + e.getMessage());
			response.setResultCode("999");
		}
		Map<String,Object> param = new HashMap<String,Object>();
		ResponseHead responseHead = ClaimInterface.getResponseHead("CLS04", "addSurveyOr");
		responseHead.setErrorMessage(response.getErrorMessage());
		responseHead.setResultCode(response.getResultCode());
		param.put("responseBody", response);
		param.put("responseHead", responseHead);
		LogUtils.info("接口修理厂或查勘同步[CLS04----->addSurveyOr]响应结果："+JsonUtil.getJsonString(param));
		String data = Encryption.encryptBASE64(JsonUtil.getJsonString(param), "utf-8");
		return data;
	}
	
	/**
	  * @Title: sendSurveyInfo
	  * 案件下发   状态：已调  接口名： DLS01
	  * @param @param request
	  * @param @return 
	  * @return String 
	  * @throws
	 */
	@RequestMapping("/sendSurveyInfo")
	@ResponseBody
	public String sendSurveyInfo(HttpServletRequest request) {
		// 响应结果
		BaseResponse response = new BaseResponse();
		try {
			// 获取参数
			Request<CliamRequest> req = JsonUtils.fromJsonClaimBase64(request.getInputStream(), CliamRequest.class);
			LogUtils.info("接口案件下发[DLS01----->sendSurveyInfo]请求参数：\n" + JsonUtils.toJson(req) + "\n");
			CliamRequest cliamRequest = JsonUtils.fromJson(JsonUtils.toJson(req.getBusinessBody()), CliamRequest.class);
			SurveyRequest srt = cliamRequest.getSendSurveyInfo();
			// 参数校验
			String valdata = UtilValidateModel.validateModel(srt);
			if (StringUtils.isNotBlank(valdata)) {
				throw new RuntimeException(valdata);
			}
			// 默认参数
			srt.setCaseStatus("0");
			srt.setCreateTime(new Date());
			List<DelegateLoss> lossItems = srt.getLossItems();
			String caseNo = srt.getCaseNo(); // 案件号
			// 分公司
			PrpmOrg prpmOrg = dbTableUtil.selectOrgByCode(srt.getUnitcode(), null);
			if (prpmOrg == null) {
				throw new RuntimeException("查勘平台：分公司代码Code：" + srt.getUnitcode() + "，在查勘未维护或错误");
			}
			// 查询案件信息
			PrpmCaseInfo caseInfo = dbTableUtil.selectCaseInfoByNo(caseNo, null);
			String orgCode = prpmOrg.getOrgCode();
			String orgId   = prpmOrg.getOrgId();
			if (caseInfo != null) {
				// 更新案件信息
				dbTableUtil.updateCaseInfo(srt, orgCode, orgId, caseInfo.getCaseInfoId());
			} else {
				srt.setCaseDealType("0"); // 未做过处理
				// 新增案件信息
				dbTableUtil.saveCaseInfo(srt, orgCode, orgId);
			}
			// 保存损失项信息
			for (DelegateLoss dl : lossItems) {
				String surveyCode = dl.getSurveyorCode();
				// 查勘员
				PrpmSurveyUser surveyUser = dbTableUtil.selectSurveyUserByCode(surveyCode);
				// userType 3:客户,2:查勘员,1:修理厂
				if (surveyUser == null && !"3".equals(dl.getLossSource())) {
					throw new RuntimeException("查勘平台：此查勘员未维护或不存在！任务类型->"+dl.getLossSource() +";查勘员号->"+surveyCode);
				}
				
				PrpmLossItem lossItem = dbTableUtil.selectLossItemByCaseNoAndLossId(caseNo, dl.getLossId());
				dl.setLossStatus("0");// 默认任务状态
				dl.setOrgCode(prpmOrg.getOrgCode());
				dl.setOrgName(prpmOrg.getOrgName());
				// 案件轨迹标示
				String optType = "01";
				if (lossItem != null) {
					// 更新损失项信息
					dbTableUtil.updateLossItem(dl, lossItem.getLossItemId(), srt.getCaseUuid());
					if(!"3".equals(dl.getLossSource())){
						optType = StringUtils.equals(lossItem.getSurveyorCode(), surveyCode) ? "01" : "02";
					}
				} else {
					// 新增损失项信息
					dbTableUtil.saveLossItem(dl, caseNo, srt.getCaseUuid());
				}
				// 保存任务历史轨迹
				LossItemHistory lh = new LossItemHistory();
				lh.setCaseNo(caseNo);
				lh.setLossItemId(dl.getLossUuid());
				lh.setLossId(dl.getLossId());
				lh.setCaseInfoId(srt.getCaseUuid());
				lh.setOptType(optType);
				lh.setLossType(dl.getLossType());
				lh.setUserCode(dl.getSurveyorCode());
				lh.setUserType(dl.getLossSource());
				dbTableUtil.saveLossItemHistory(lh);
			}

			// 通知核心
			ClaimInterface.notificationTask(caseNo, null);
			response.setResultCode("000");
			response.setErrorMessage("查勘平台：处理案件下发成功");
		} catch (Exception e) {
			LogUtils.error("接口案件下发[DLS01----->sendSurveyInfo]服务器处理异常：\n", e);
			String message = "查勘平台：处理案件下发接口异常";
			if (e instanceof RuntimeException) {
				message = e.getMessage();
			}
			response.setResultCode("999");
			response.setErrorMessage(message);
		}
		ResponseHead responseHead = ClaimInterface.getResponseHead("DLS01", "sendSurveyInfo");
		responseHead.setErrorMessage(response.getErrorMessage());
		responseHead.setResultCode(response.getResultCode());
		// 响应结果
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("responseBody", response);
		param.put("responseHead", responseHead);
		LogUtils.info("接口案件下发[DLS01----->sendSurveyInfo]返回结果：\n" + JsonUtil.getJsonString(param));
		String data = Encryption.encryptBASE64(JsonUtil.getJsonString(param), "utf-8");
		return data;
	}
	
	
	
	
	/**
	  * @Title: queryCaseVideoInfo
	  * 查询案件的视频连线信息 状态：未调 接口名：DLS05
	  * @param @param request
	  * @param @return 
	  * @return String 
	  * @throws
	 */
	@RequestMapping("/queryCaseVideoInfo")
	@ResponseBody
	public String queryCaseVideoInfo(HttpServletRequest request){
		//响应结果
		CliamResponse response = new CliamResponse();
		ChangeTaskStatusResponse changeTaskStatusResponse = new ChangeTaskStatusResponse();
		ResponseHead responseHead = ClaimInterface.getResponseHead("DLS05", "queryCaseVideoInfo");
		try {
			Request<ChangeCaseVideoRequest> req = JsonUtils.fromJsonClaimBase64(request.getInputStream(), ChangeCaseVideoRequest.class);
			LogUtils.info("接口查询案件的视频连线信息[DLS05----->queryCaseVideoInfo]接收消息：\n"+JsonUtils.toJson(req)+"\n");
			CliamRequest cliamRequest =  JsonUtils.fromJson(JsonUtils.toJson(req.getBusinessBody()), CliamRequest.class);  
			List<String> caseUuidList = cliamRequest.getQueryCaseVideoInfo().getCaseUuidList();
			List<CaseInfoDto> caseInfoList = new ArrayList<CaseInfoDto>();
			List<String> errorCaseIdList = new ArrayList<String>();
			for (String caseUuId : caseUuidList) {
				CaseInfoDto caseInfoDto = new CaseInfoDto();
				PrpmCaseInfo caseInfo = dbTableUtil.selectCaseInfoByNo(null, caseUuId);
				if(caseInfo == null){
					errorCaseIdList.add(caseUuId);
					continue;
				}
				PrpmOrg org = dbTableUtil.selectOrgByCode(caseInfo.getOrgCode(),null);
				if(org == null){
					continue;
				}
				caseInfoDto.setAgtID("");
				caseInfoDto.setCaseUuid(caseUuId);
				caseInfoDto.setSkillID(org.getOrgSkill());
				caseInfoDto.setUnitCode(org.getOrgCode());
				caseInfoDto.setVcid(org.getOrgVcid());
				caseInfoList.add(caseInfoDto);
			}
			changeTaskStatusResponse.setCaseVideoList(caseInfoList);
			if(caseInfoList.size() == 0){
				responseHead.setErrorMessage("查勘平台：查询案件的视频连线信息失败");
				responseHead.setResultCode("999");
				LogUtils.info("案件Id不存在列表："+JsonUtils.toJson(errorCaseIdList));
			}else{
				responseHead.setErrorMessage("查勘平台：查询案件的视频连线信息成功");
				responseHead.setResultCode("000");
			}
			
		} catch (Exception e) {
			LogUtils.error("接口查询案件的视频连线信息[DLS05----->queryCaseVideoInfo]返回异常",e);
			responseHead.setErrorMessage("查勘平台：查询案件的视频连线失败");
			responseHead.setResultCode("999");
		}
		Map<String,Object> param = new HashMap<String,Object>();
		response.setCaseVideoInfo(changeTaskStatusResponse);
		param.put("businessBody", response);
		param.put("responseHead", responseHead);
		LogUtils.info("接口查询案件的视频连线信息[DLS05----->queryCaseVideoInfo]返回结果：\n"+JsonUtil.getJsonString(param)+"\n");
		String data = Encryption.encryptBASE64(JsonUtil.getJsonString(param), "utf-8");
		return data;
	}
	
	/**
	  * @Title: 任务状态变更 changeTaskStatus
	  *  状态：已调  接口名：DLS03
	  * @param @param request
	  * @param @return 设定文件
	  * @return ChangeTaskStatusResponse 
	  * @throws 
	 */
	@RequestMapping("/changeTaskStatus")
	@ResponseBody
	public String changeTaskStatus(HttpServletRequest request){
		//响应参数
		BaseResponse response = new BaseResponse();
		try {
			Request<CliamRequest> req = JsonUtils.fromJsonClaimBase64(request.getInputStream(), CliamRequest.class);
			LogUtils.info("接口任务状态变更[DLS03----->changeTaskStatus]接收参数：\n"+JsonUtils.toJson(req)+"\n");
			BaseRequest cs = JsonUtils.fromJson(JsonUtils.toJson(req.getBusinessBody()), BaseRequest.class);
			ChangeTaskStatusRequest cr = cs.getChangeTaskStatus();
			//参数校验
			String valdata = UtilValidateModel.validateModel(cr);
			if(StringUtils.isNotBlank(valdata)){
				throw new RuntimeException(valdata);
			}
			String caseNo = cr.getCaseNo(); //案件号
			PrpmCaseInfo caseInfo = dbTableUtil.selectCaseInfoByNo(caseNo,null);
			if(caseInfo == null){
				response.setErrorMessage("查勘平台：案件信息错误或不存在，案件号："+caseNo);
				response.setResultCode("999");
			}else{
				//整案注销
				if("3".equals(cr.getType())){
					List<PrpmLossItem> lossItemList = dbTableUtil.selectLossItemByCaseNo(caseNo);
					boolean isPay  = false; //方式方式
					boolean isBill = false; //是否计费
					for (PrpmLossItem pm : lossItemList) {
						String status = null;
						if (!"0".equals(pm.getLossDealType())) {
							status = Constants.CASE_AFTER_CONNECTCANCEL;
							isBill = true;
						} else {
							status = Constants.CASE_BEFORE_CONNECTCANCEL;
						}
						// 收费方式
						if(pm.getUserType() == 3){
							isPay = true;
						}
						dbTableUtil.updateLossItemStatusByLossId(status,pm.getLossItemId());
					}
					//收费方式
					String billType = isBill?isPay?"4":"3":"1";
					dbTableUtil.updateCaseInfoStatusByCaseNo("2",billType, caseInfo.getCaseInfoId());
				}else{
					// 更新任务状态
					for (DelegateLossInfo dl : cr.getDelegateLoss()) {
						// 查询任务信息  注销前状态 3：任务注销 4：转常规
						PrpmLossItem lossItem = dbTableUtil.selectLossItemByCaseNoAndLossId(caseNo, dl.getLossId());
						if(lossItem != null){
							// 状态处理
							if("1".equals(dl.getStatus())){
								// 申请改派
								dl.setStatus(Constants.LOSS_STATUS_TAYPE3);
							}else{
								if(!"0".equals(lossItem.getLossDealType())){
									dl.setStatus(Constants.LOSS_STATUS_TAYPE6);
								}else{
									dl.setStatus(Constants.LOSS_STATUS_TAYPE5);
								}
							}
							// 更新任务状态
							dbTableUtil.updateLossItemStatusById(dl);
							// 保存任务历史轨迹
							LossItemHistory lh = new LossItemHistory();
							lh.setCaseNo(caseNo);
							lh.setLossHisId(UUIDUtils.uuid());
							lh.setLossItemId(lossItem.getLossItemId());
							lh.setLossId(dl.getLossId());
							lh.setCaseInfoId(caseInfo.getCaseInfoId());
							lh.setOperateTime(new Date());
							lh.setOptType(StringUtil.getOptNumber(dl.getStatus()));
							lh.setLossType(dl.getLossType());
							lh.setUserCode(lossItem.getSurveyorCode());
							int plat = StringUtils.equals("1", dl.getSource())? 2 : 3;
							lh.setReassignPlat(plat);
							dbTableUtil.saveLossItemHistory(lh);
						}
					}
				}
				response.setErrorMessage("查勘平台：任务状态同步成功");
				response.setResultCode("000");
			}
		} catch (Exception e) {
			LogUtils.error("接口任务状态变更[DLS03----->changeTaskStatus]响应异常：\n",e);
			response.setErrorMessage("任务状态同步异常");
			response.setResultCode("999");
		}
		Map<String,Object> param = new HashMap<String,Object>();
		ResponseHead responseHead = ClaimInterface.getResponseHead("DLS03", "changeTaskStatus");
		responseHead.setErrorMessage(response.getErrorMessage());
		responseHead.setResultCode(response.getResultCode());
		param.put("responseBody", response);
		param.put("responseHead", responseHead);
		LogUtils.info("接口理任务状态变更[DLS03----->changeTaskStatus]响应参数：\n"+JsonUtil.getJsonString(param));
		String data = Encryption.encryptBASE64(JsonUtil.getJsonString(param), "utf-8");
		return data;
	}
	
	
	/**
	  * @Title: 状态：已调; 接口名：DLS02 createDocumentTask
	  * @Description: 调度创建单证任务同步到查勘
	  * @param @param request
	  * @param @return 设定文件
	  * @return String 返回类型
	  * @throws
	 */
	@RequestMapping("/CreateDocumentTask")
	@ResponseBody
	public String createDocumentTask(HttpServletRequest request) {
		BaseResponse response = new BaseResponse();
		try {
			Request<CliamRequest> req = JsonUtils.fromJsonClaimBase64(request.getInputStream(), CliamRequest.class);
			LogUtils.info("接口调度创建单证任务同步查勘[DLS02----->createDocumentTask]接收参数："+JsonUtils.toJson(req)+"\n");
			CliamRequest cliamRequest = JsonUtils.fromJson(JsonUtils.toJson(req.getBusinessBody()), CliamRequest.class);
			CreateDocumentTask createTask = cliamRequest.getCreateDocumentTask();
			//参数校验
			String valdata = UtilValidateModel.validateModel(createTask);
			if(StringUtils.isNotBlank(valdata)){
				throw new RuntimeException(valdata);
			}
			PrpmOrg prpmOrg = dbTableUtil.selectOrgByCode(createTask.getCompanyCode(), null);
			if (prpmOrg == null) {
				throw new RuntimeException("查勘平台：分公司代码Code："+createTask.getCompanyCode()+"，在查勘未维护或错误");
			}
			String caseNo = createTask.getCaseNo();
			// 查询核心P12接口获取案件信息
			ResultInfo resultInfo = ClaimInterface.findCaseInfo(caseNo);
			if (resultInfo.getCaseInfo() == null) {
				throw new RuntimeException("查勘平台：调用P12接口获取案件信息，"+resultInfo.getResultMsg());
			}
			// 任务类型 0:新建，1改派
			String taskType = createTask.getTaskType();
			String userCode = createTask.getUserCode();
			String newType = null;
			if ("0".equals(taskType)) {
				// 案件信息
				PrpmCaseInfoCyp caseInfoCyp = dbTableUtil.selectCaseInfoCypByNo(caseNo);

				// 任务列表
				List<PrpmLossItemCyp> lossListCypList = dbTableUtil.
						selectCaseInfoLossItemCyp(caseNo, Constants.LOSS_ITEMTYPE9,Constants.LOSS_HANDLESTATUS2, false);
				if (lossListCypList.size() > 0) {
					throw new RuntimeException("查勘平台：系统中已经存在未完成的单证任务,案件编号：" + caseNo);
				}
				InjuryTaskDis it = new InjuryTaskDis();
				it.setCaseNo(caseNo);
				it.setLicenseNo(createTask.getLicenseNo());
				it.setContact(createTask.getContact());
				it.setContactPhone(createTask.getContactPhone());
				it.setDamageDate(DateUtil.formatDateTime(createTask.getDamageDate()));
				it.setDamagePlace(createTask.getDamagePlace());
				it.setCreateTime(new Date());
				List<PolicyInfo> policyInfoList = resultInfo.getCaseInfo().getPolicyLst();
				// 添加保单信息 
				for (PolicyInfo policyInfo : policyInfoList) {
					if (policyInfo.getSpeciesName().contains("商业险")) {
						it.setPolicyCode(policyInfo.getPolicyNo());
						it.setInsuranceType(policyInfo.getSpeciesName());
						it.setInsuranceClass(policyInfo.getCategoryName());
						it.setPolicyHolder(policyInfo.getAppliName());
						it.setUserName(policyInfo.getInsuredName());
					} 
					// 
					if(policyInfoList.size() == 1){
						it.setPolicyCode(policyInfo.getPolicyNo());
						it.setInsuranceType(policyInfo.getSpeciesName());
						it.setInsuranceClass(policyInfo.getCategoryName());
						it.setPolicyHolder(policyInfo.getAppliName());
						it.setUserName(policyInfo.getInsuredName());
					}
				}
				String caseInfoCypId = UUIDUtils.uuid();
				if (caseInfoCyp == null) {
					// 保存案件信息
					dbTableUtil.saveCaseInfoCyp(it,prpmOrg.getOrgFlag(), prpmOrg.getOrgCode(), caseInfoCypId);
				}
				String lossItemCypId = UUIDUtils.uuid();
				// 保存任务信息
				it.setClaimStatus("1"); // 认领状态
				it.setCollectTime(createTask.getCollectTime());
				// 设置
				setInjuryTaskDis(it, createTask, caseNo);
				// 案件编号
				caseInfoCypId = caseInfoCyp != null ? caseInfoCyp.getCaseInfoCypId() : caseInfoCypId;
				// 保存记录
				dbTableUtil.saveLossItemCyp(it, lossItemCypId, caseInfoCypId);
				// 保存历史记录
				dbTableUtil.saveLossItemHistryCyp(UUIDUtils.uuid(), lossItemCypId);
				
				response.setErrorMessage("查勘平台：调度创建单证任务同步处理成功");
				response.setResultCode("000");
				newType = Constants.MOBILE_NEW_TYPE14;
			} else {
				// 案件信息
				PrpmCaseInfoCyp caseInfoCyp = dbTableUtil.selectCaseInfoCypByNo(caseNo);
				if (caseInfoCyp == null) {
					throw new RuntimeException("查勘平台:系统中没有存在需要改派的单证任务,案件编号：" + caseNo);
				}
				// 查询历史记录
				List<PrpmLossItemCyp> sendLossItemList = dbTableUtil.selectSendLossItemCyp(caseNo,
						Constants.LOSS_ITEMTYPE9);
				if (sendLossItemList.size() == 0) {
					throw new RuntimeException("查勘平台:系统中没有存在需要改派的单证任务,案件编号：" + caseNo);
				}
				
				for (PrpmLossItemCyp lossItem : sendLossItemList) {
					InjuryTaskDis it = new InjuryTaskDis();
					setInjuryTaskDis(it, createTask, caseNo);
					if("1".equals(createTask.getClaimFlag())){
						it.setHandleStatus(Constants.LOSS_HANDLESTATUS8);
					}else{
						it.setHandleStatus(Constants.LOSS_HANDLESTATUS7); //7改派未认领
					}
					// 更新任务信息
					dbTableUtil.updateLossItemCyp(it,lossItem.getLossItemCypId(),caseInfoCyp.getCaseInfoCypId());
					// 加入人伤记录
					dbTableUtil.saveLossItemHistryCyp(UUIDUtils.uuid(), lossItem.getLossItemCypId());
					// 历史记录
					String id = dbTableUtil.selectLossItemHistoryByCaseNo(caseNo, Constants.LOSS_ITEMTYPE9);
					if (StringUtils.isNotBlank(id)) {
						// 更新历史
						dbTableUtil.updateLossItemHistoryById(id, createTask.getReassignMsg());
					}
					response.setErrorMessage("查勘平台：调度创建单证任务同步处理成功");
					response.setResultCode("000");
					newType = Constants.MOBILE_NEW_TYPE15;
				}
			}
			// 消息推送
			String message = "您有新的收单任务，请处理，案件号：" + caseNo;
			pushMessageInfoToApp(caseNo, newType, userCode, 2, message);
			
		} catch (Exception e) {
			LogUtils.error("接口调度创建单证任务同步查勘[DLS02----->createDocumentTask]服务器异常：\n", e);
			String errorMsg = "查勘平台：调度创建单证任务同步查勘未知异常!";
			if (e instanceof RuntimeException) {
				errorMsg = e.getMessage();
			}
			response.setErrorMessage(errorMsg);
			response.setResultCode("999");
		}
		ResponseHead responseHead = ClaimInterface.getResponseHead("DLS02", "createDocumentTask");
		responseHead.setErrorMessage(response.getErrorMessage());
		responseHead.setResultCode(response.getResultCode());
		// 响应
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("responseBody", response);
		param.put("responseHead", responseHead);
		LogUtils.info("接口调度创建单证任务同步查勘[DLS02----->createDocumentTask]响应结果：\n" + JsonUtil.getJsonString(param));
		String data = Encryption.encryptBASE64(JsonUtil.getJsonString(param), "utf-8");
		return data;
	}
	
	
	/**
	  * @Title: getInjuryTaskDis
	  * @Description: 构建参数
	  * @param @param createTask
	  * @param @param caseNo
	  * @param @return
	  * @param @throws Exception 设定文件
	  * @return InjuryTaskDis 返回类型
	  * @throws
	 */
	private void setInjuryTaskDis(InjuryTaskDis it, CreateDocumentTask createTask, String caseNo) throws Exception {
		// 保存任务信息
		// it.setClaimStatus("1"); // 认领状态
		it.setLossStatus("0");
		it.setCaseNo(caseNo);
		it.setLossType("9");// 损失类型
		it.setHandleStatus("0"); // 处理状态：未上传
		if ("1".equals(createTask.getClaimFlag())) {
			it.setHandleStatus("8"); // 处理状态：已上传
		}
		it.setUpdateTime(new Date());
		it.setCollectAddress(createTask.getCollectAddress());
		it.setCollectTime(createTask.getCollectTime());
		it.setInformation(createTask.getInformation());
		it.setCreateUser("95505");
		it.setUpdateUser("95505");
		// 查勘员信息
		it.setSurveyorCode(createTask.getUserCode());
		it.setSurveyorName(createTask.getUserCode());
		PrpmSurveyUser user = dbTableUtil.selectSurveyUserByCode(createTask.getUserCode());
		if (user != null) {
			it.setSurveyorCode(user.getSurveyUserCode());
			it.setSurveyorName(user.getSurveyName());
		}
		it.setRemark("首次调度");
		if (StringUtils.isNotBlank(createTask.getRemark())) {
			it.setRemark(createTask.getRemark());
		}
	}
	
	/**
	  * @Title: addSynCheckUser
	  * @Description: 查勘员修理厂同步
	  * @param @param request
	  * @param @return 设定文件
	  * @return String 返回类型
	  * @throws
	 */
	@RequestMapping("/synCheckUser")
	@ResponseBody
	public String addSynCheckUser(HttpServletRequest request){
		ResponseHead responseHead = new ResponseHead();
		try {
			//获取请求参数
			Request<CliamRequest> ur = JsonUtils.fromJsonClaimBase64(request.getInputStream(), CliamRequest.class);
			LogUtils.info("接口查勘员修理厂同步结果[CLS06----->synCheckUser]接收参数：\n"+JsonUtils.toJson(ur)+"\n");	   
			//解析实体
			CliamRequest cliamRequest = JsonUtils.fromJson(JsonUtils.toJson(ur.getBusinessBody()), CliamRequest.class);
			SynCheckUser synuser = cliamRequest.getSynGarageInfo();
			//参数校验
			String valdata = UtilValidateModel.validateModel(synuser);
			if(StringUtils.isNotBlank(valdata)){
				throw new RuntimeException(valdata);
			}
			PrpmOrg prpmOrg = dbTableUtil.selectOrgByCode(synuser.getUnitCode(), null);
			if(prpmOrg == null){
				throw new RuntimeException("查勘平台：分公司代码Code："+synuser.getUnitCode()+"，在查勘未维护或错误");
			}
			PrpmSurveyUser surveyUser = dbTableUtil.selectSurveyUserByCode(synuser.getSurveyNo());
			AddSurvry ads = new AddSurvry();
			ads.setUserName(synuser.getSurveyName());
			ads.setUserCode(synuser.getSurveyNo());
			ads.setPhone(synuser.getSurveyPhone());
			ads.setAddress(synuser.getAddress());
			ads.setOrgCode(prpmOrg.getOrgCode());
			ads.setUserType(synuser.getSituation());
			ads.setStatus(synuser.getValidStatus());
			String orgId = prpmOrg.getOrgId();
			if(surveyUser == null){
				//新增
				dbTableUtil.savePrpmSurveyUser(ads, orgId);
			}else{
				//更新
				dbTableUtil.updatePrpmSurveyUserById(ads, orgId, surveyUser.getSurveyUserId());
			}
			responseHead.setResultCode("000");
			responseHead.setErrorMessage("查勘平台：同步查勘员或修理厂成功");
		} catch (Exception e) {
			LogUtils.error("接口同步查勘员修理厂信息[CLS07----->synCheckUser]服务器异常：\n", e);
			String errorMsg = "查勘平台：同步查勘员修理厂信息未知或网络异常";
			if (e instanceof RuntimeException) {
				errorMsg = e.getMessage();
			}
			responseHead.setErrorMessage(errorMsg);
			responseHead.setResultCode("999");
		}
		Map<String,Object> param = new HashMap<String,Object>();
		BaseResponse response = new BaseResponse();
		response.setErrorMessage(responseHead.getErrorMessage());
		response.setResultCode(responseHead.getResultCode());
		param.put("businessBody",response);
		param.put("responseHead",responseHead);
		LogUtils.info("接口同步查勘员修理厂信息[CLS07----->synCheckUser]响应结果：\n" + JsonUtil.getJsonString(param));
		String data = Encryption.encryptBASE64(JsonUtil.getJsonString(param), "utf-8");
		return data;
	}
	
	
	/**
	 * 
	  * @Title: 状态：已调试：接口名： C02
	  * @Description:endInfo 
	  * 理赔系统通知查勘系统，案件已经报案注销（取证前注销）
	  * @param @param request
	  * @param @return 设定文件
	  * @return String 返回类型
	  * @throws
	 */
	@RequestMapping("/endInfo")
	@ResponseBody
	public String endInfo(HttpServletRequest request) {
		ResponseHead responseHead = new ResponseHead();
		try {
			// 获取参数
			Request<CliamRequest> ur = JsonUtils.fromJsonClaimBase64(request.getInputStream(), CliamRequest.class);
			CliamRequest req = JsonUtils.fromJson(JsonUtils.toJson(ur.getBusinessBody()), CliamRequest.class);
			LogUtils.info("接口核损完成通知[C02----->endInfo]接收报文：\n" + JsonUtils.toJson(req));
			EndInfoRequest endinfo = req.getEndCaseInfo();
			// 参数校验
			String valdata = UtilValidateModel.validateModel(endinfo);
			if (StringUtils.isNotBlank(valdata)) {
				throw new RuntimeException(valdata);
			}
			// 案件号
			String caseNo = endinfo.getCaseNo();
			// 查询案件信息
			PrpmCaseInfo caseInfo = dbTableUtil.selectCaseInfoByNo(caseNo, null);
			if (caseInfo == null) {
				throw new RuntimeException("查勘平台：案件号错误或信息不存在，案件号：" + caseNo);
			}
			// 查询任务
			PrpmLossItem lossItem = dbTableUtil.selectLossItemByCaseNoAndLossId(caseNo, endinfo.getLossId());
			// 更新定损完成待确认
			dbTableUtil.updateLossItemStatusByCaseNoLossId(String.valueOf(Constants.LOSS_TBC), endinfo.getLossId(),caseNo);
			if (lossItem != null) {
				// 发送信息推送
				String message = null;
				String mobileCode = lossItem.getSurveyorCode();
				if (lossItem.getUserType() == 3) {
					message = "您的案件" + caseInfo.getCaseNo() + "有新的定损单,请在“我的理赔”中点选“定损清单”，如无异议请点击“同意”";
					mobileCode = lossItem.getMobile();
				} else {
					message = "案件" + caseInfo.getCaseNo() + "有新的定损单，请在定损中心查看。";
				}
				// 消息推送
				pushMessageInfoToApp(caseNo, Constants.MOBILE_NEW_TYPE3, mobileCode,lossItem.getUserType(), message);
			}
			responseHead.setErrorMessage("查勘平台：核损完成通知成功");
			responseHead.setResultCode("000");
		} catch (Exception e) {
			LogUtils.error("接口核损完成通知[C02----->endInfo]服务器异常：\n", e);
			String msg = "未知或网络异常";
			if (e instanceof RuntimeException) {
				msg = e.getMessage();
			}
			responseHead.setErrorMessage("查勘平台：核损完成通知" + msg);
			responseHead.setResultCode("999");
		}
		Map<String, Object> param = new HashMap<String, Object>();
		SendSurveyInfoResponse response = new SendSurveyInfoResponse();
		response.setResponseHead(responseHead);
		param.put("businessBody", new BaseResponse(responseHead.getResultCode(), responseHead.getErrorMessage()));
		param.put("responseHead", responseHead);
		LogUtils.info("接口核损完成通知[C02----->endInfo]响应结果：\n" + JsonUtil.getJsonString(param));
		String data = Encryption.encryptBASE64(JsonUtil.getJsonString(param), "utf-8");
		return data;
	}
	
	
	/**
	  * @Title:状态：已调试 sendNoResult C05
	  * @Description: 案件转正常案件
	  * @param @param request
	  * @param @return 设定文件
	  * @return String 返回类型
	  * @throws
	 */
	@RequestMapping("/sendNoResult")
	@ResponseBody
	public String sendNoResult(HttpServletRequest request){
		ResponseHead responseHead = new ResponseHead();
		responseHead.setIsPay("0");
		try {
			//获取参数
			Request<CliamRequest> ur = JsonUtils.fromJsonClaimBase64(request.getInputStream(), CliamRequest.class);
			LogUtils.info("接口案件转正常案件[C05----->sendNoResult]接收报文：" + JsonUtils.toJson(ur));
			SendSurveyRequest sendInfo = JsonUtils.fromJson(JsonUtils.toJson(ur.getBusinessBody()), SendSurveyRequest.class);
			//String caseNo = sendInfo.getCaseNo();
			//参数校验
			String valdata = UtilValidateModel.validateModel(sendInfo);
			if(StringUtils.isNotBlank(valdata)){
				throw new RuntimeException(valdata);
			}
			responseHead.setErrorMessage("查勘平台：案件转正常案成功");
			responseHead.setResultCode("999");
		} catch (Exception e) {
			LogUtils.error("接口案件转正常案件[C05----->sendNoResult]服务器异常：\n", e);
			String msg = "未知或网络异常";
			if (e instanceof RuntimeException) {
				msg = e.getMessage();
			}
			responseHead.setErrorMessage("查勘平台：案件转正常案件" + msg);
			responseHead.setResultCode("999");
		}
		Map<String, Object> param = new HashMap<String, Object>();
		SendSurveyInfoResponse response = new SendSurveyInfoResponse();
		response.setResponseHead(responseHead);
		param.put("businessBody", new BaseResponse(responseHead.getResultCode(), responseHead.getErrorMessage()));
		param.put("responseHead", responseHead);
		LogUtils.info("接口案件转正常案件[C05----->sendNoResult]响应结果：\n" + JsonUtil.getJsonString(param));
		String data = Encryption.encryptBASE64(JsonUtil.getJsonString(param), "utf-8");
		return data;
	}
	
	
	/**
	  * @Title:状态：已调试 cancelCaseInfo C07
	  * @Description: 报案注销通知
	  * @param @param request
	  * @param @return 设定文件
	  * @return String 返回类型
	  * @throws
	 */
	@RequestMapping("/cancelInfo")
	@ResponseBody
	public String cancelCaseInfo(HttpServletRequest request){
		ResponseHead responseHead = new ResponseHead();
		try {
			//获取参数
			Request<CliamRequest> ur = JsonUtils.fromJsonClaimBase64(request.getInputStream(), CliamRequest.class);
			CaseInfoCancelRequest cancelCase =  JsonUtils.fromJson(JsonUtils.toJson(ur.getBusinessBody()), CaseInfoCancelRequest.class);
			//参数校验
			String valdata = UtilValidateModel.validateModel(cancelCase);
			if(StringUtils.isNotBlank(valdata)){
				throw new RuntimeException(valdata);
			}
			LogUtils.info("接口报案注销通知[C07----->cancelInfo]接收参数：\n" + JsonUtils.toJson(cancelCase)+"\n");
			String caseNo = cancelCase.getCaseNo();
			PrpmCaseInfo caseInfo = dbTableUtil.selectCaseInfoByNo(caseNo, null);
			if (caseInfo == null) {
				throw new RuntimeException("查勘平台：案件号错误或不存在，案件号："+caseNo);
			}
			responseHead.setErrorMessage("查勘平台：报案注销通知成功");
			responseHead.setResultCode("000");
		} catch (Exception e) {
			LogUtils.error("接口报案注销通知[C07----->cancelCaseInfo]服务器异常：\n", e);
			String msg = "未知或网络异常";
			if (e instanceof RuntimeException) {
				msg = e.getMessage();
			}
			responseHead.setErrorMessage("查勘平台：报案注销通知" + msg);
			responseHead.setResultCode("999");
		}
		Map<String, Object> param = new HashMap<String, Object>();
		GetPaperDocResponse response = new GetPaperDocResponse();
		response.setResponseHead(responseHead);
		param.put("businessBody", new BaseResponse(responseHead.getResultCode(), responseHead.getErrorMessage()));
		param.put("responseHead", responseHead);
		LogUtils.info("接口报案注销通知[C07----->cancelCaseInfo]响应结果：\n" + JsonUtil.getJsonString(param));
		String data = Encryption.encryptBASE64(JsonUtil.getJsonString(param), "utf-8");
		return data;
	}
	
	
	/**
	  * @Title:状态：已调试 reuploadInfo C08
	  * @Description: 单证补传通知
	  * @param @param request
	  * @param @return 设定文件
	  * @return String 返回类型
	  * @throws
	 */
	@RequestMapping("/reuploadInfo")
	@ResponseBody
	public String reuploadInfo(HttpServletRequest request) {
		ResponseHead responseHead = new ResponseHead();
		try {
			Request<CliamRequest> ur = JsonUtils.fromJsonClaimBase64(request.getInputStream(), CliamRequest.class);
			ReuploadInfoRequest reupload = JsonUtils.fromJson(JsonUtils.toJson(ur.getBusinessBody()), ReuploadInfoRequest.class);
			// 参数校验
			String valdata = UtilValidateModel.validateModel(reupload);
			if (StringUtils.isNotBlank(valdata)) {
				throw new RuntimeException(valdata);
			}
			String caseNo = reupload.getCaseNo();
			LogUtils.info("接口单证补传通知[C08----->reuploadInfo]接收报文：\n" + JsonUtils.toJson(reupload));
			PrpmCaseInfo caseInfo = dbTableUtil.selectCaseInfoByNo(caseNo, null);
			if (caseInfo == null) {
				throw new RuntimeException("查勘平台：案件号错误或不存在，案件号："+caseNo);
			}
			// 查询任务
			PrpmLossItem lossItem = dbTableUtil.selectLossItemByCaseNoAndLossId(caseNo, reupload.getLossId());
			if (lossItem != null) {
				// 消息推送
				String message = null;
				String mobileCode = lossItem.getSurveyorCode();
				int userType = lossItem.getUserType();
				if (userType == 3) {
					message = "请点选“我的理赔”，点击“上传照片”。";
					mobileCode = lossItem.getMobile();
				} else {
					message = "您有一个单证补传任务，报案号：" + caseNo + "，补传说明：" + reupload.getReuploadReamrk() + "。";
				}
				// 推送消息
				pushMessageInfoToApp(caseNo, Constants.MOBILE_NEW_TYPE6, mobileCode, userType, message);
			} else {
				LogUtils.info("查勘平台：单证补传通知个推消息失败：案件号为" + caseNo);
			}
			responseHead.setErrorMessage("查勘平台：单证补传通知成功");
			responseHead.setResultCode("000");
		} catch (Exception e) {
			LogUtils.error("接口单证补传通知[C08----->reuploadInfo]服务器异常：\n", e);
			String msg = "未知或网络异常";
			if (e instanceof RuntimeException) {
				msg = e.getMessage();
			}
			responseHead.setErrorMessage("查勘平台：单证补传通知" + msg);
			responseHead.setResultCode("999");
		}
		Map<String, Object> param = new HashMap<String, Object>();
		SendSurveyInfoResponse response = new SendSurveyInfoResponse();
		response.setResponseHead(responseHead);
		param.put("businessBody", new BaseResponse(responseHead.getResultCode(), responseHead.getErrorMessage()));
		param.put("responseHead", responseHead);
		LogUtils.info("接口单证补传通知[C08----->endInfo]响应结果：\n" + JsonUtil.getJsonString(param));
		String data = Encryption.encryptBASE64(JsonUtil.getJsonString(param), "utf-8");
		return data;
	}
	
	
	
	/**
	  * @Title:状态：已调试	 getPaperDoc C09
	  * @Description: 补传纸质单证通知
	  * @param @param request
	  * @param @return 设定文件
	  * @return String 返回类型
	  * @throws
	 */
	@RequestMapping("/getPaperDoc")
	@ResponseBody
	public String getPaperDoc(HttpServletRequest request){
		ResponseHead responseHead = new ResponseHead();
		try {
			//获取参数
			Request<CliamRequest> ur = JsonUtils.fromJsonClaimBase64(request.getInputStream(), CliamRequest.class);
			GetPaperDocRequest paperDoc = JsonUtils.fromJson(JsonUtils.toJson(ur.getBusinessBody()), GetPaperDocRequest.class);
			//参数校验
			String valdata = UtilValidateModel.validateModel(paperDoc);
			if(StringUtils.isNotBlank(valdata)){
				throw new RuntimeException(valdata);
			}
			LogUtils.info("接口纸质单证收集[C08----->getPaperDoc]接收报文：" + JsonUtils.toJson(paperDoc));
			String caseNo = paperDoc.getCaseNo();
			String docName = paperDoc.getDocName();
			// 消息推送
			String message = null;
			if ("0".equals(paperDoc.getIsTask())) {
				message = "案件" + caseNo + "的纸质单证已由单证人员" + docName + "成功收集。";
			} else {
				message = "案件" + caseNo + "，请将下列纸质单证提交至单证人员：" + docName;
			}
			String newsType = null;
			if ("0".equals(paperDoc.getIsTask())) {
				newsType = Constants.MOBILE_NEW_TYPE11;// 纸质单证完成
			} else {
				newsType = Constants.MOBILE_NEW_TYPE9;	// 纸质单证补传推送
			}
			// 推送消息
			pushMessageInfoToApp(caseNo, newsType, paperDoc.getSurveyNo(), 2, message);
			responseHead.setErrorMessage("查勘平台：纸质单证收集成功");
			responseHead.setResultCode("000");
		} catch (Exception e) {
			LogUtils.error("接口纸质单证收集[C08----->getPaperDoc]服务器异常：\n", e);
			String msg = "未知或网络异常";
			if (e instanceof RuntimeException) {
				msg = e.getMessage();
			}
			responseHead.setErrorMessage("查勘平台：纸质单证收集" + msg);
			responseHead.setResultCode("999");
		}
		Map<String, Object> param = new HashMap<String, Object>();
		GetPaperDocResponse response = new GetPaperDocResponse();
		response.setResponseHead(responseHead);
		param.put("businessBody", new BaseResponse(responseHead.getResultCode(), responseHead.getErrorMessage()));
		param.put("responseHead", responseHead);
		LogUtils.info("接口纸质单证收集[C09----->endInfo]响应结果：\n" + JsonUtil.getJsonString(param));
		String data = Encryption.encryptBASE64(JsonUtil.getJsonString(param), "utf-8");
		return data;
	}
	
	/**
	  * @Title: pushMessageInfoToApp
	  * @Description: 消息推送
	  * @param @param caseNo
	  * @param @param newType
	  * @param @param mcode
	  * @param @param userType
	  * @param @param message 设定文件
	  * @return void 返回类型
	  * @throws
	 */
	public void pushMessageInfoToApp(String caseNo,String newType,String mcode,int userType,String message){
		String mobile = mcode;
		String userCode = mcode;
		// 非自助
		if(userType != 3){
			try {
				// 查询查勘员信息
				PrpmSurveyUser surveyUser = dbTableUtil.selectSurveyUserByCode(mcode);
				if(surveyUser != null){
					mobile = surveyUser.getMobile();
				}
				userCode= mcode;
			} catch (Exception e) {
				LogUtils.error("查询查勘员信息失败.",e);
			}
		}
		// 推送
		HttpRequestUtil.sendMessageInfo(caseNo,newType,userCode,mobile, userType, message);
	}
	
}
